package com.yl.module.property.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yl.module.property.mapper.PropertyRunDataMapper;
import com.yl.module.property.service.PropertyRunDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.yl.module.property.domain.vo.PropertyRunDataVO;
import com.yl.module.property.domain.dto.PropertyRunDataDTO;
import com.yl.module.property.domain.PropertyRunData;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;

/**
 * 智能资产运行数据表 此表数据来源于建科 Service实现类
 * @author makejava
 * @date 2024-10-23 15:54:16
 */
@Service
@Slf4j
public class PropertyRunDataServiceImpl extends ServiceImpl<PropertyRunDataMapper, PropertyRunData> implements PropertyRunDataService {

	@Autowired
	PropertyRunDataMapper propertyRunDataMapper;

   /**
	 * 查询所有
	 */
	@Override
	public List<PropertyRunDataVO> getAll(){
		List<PropertyRunData> list = this.list();
		List<PropertyRunDataVO> result = BeanUtil.copyToList(list, PropertyRunDataVO.class);
		return result;
	}

	/**
     * 分页查询
     */
	@Override
    public Page<PropertyRunData> getPage(PropertyRunDataDTO dto){
		//创建分页对象
		Page<PropertyRunData> page = new Page(dto.getPageNum(), dto.getPageSize());
		//dto查询条件转分页条件
		LambdaQueryWrapper<PropertyRunData> lqw = new LambdaQueryWrapper<>();
		Page<PropertyRunData> result = propertyRunDataMapper.selectPage(page, lqw);
		return result;
	}

	/**
	 * 通过主键查询
	 */
	@Override
	public PropertyRunDataVO getByKey(Integer id){
		PropertyRunData entity = super.getById(id);
		PropertyRunDataVO result = BeanUtil.copyProperties(entity, PropertyRunDataVO.class);
        return result;
    }

	/**
	 * 添加
	 */
	@Override
	public Integer add(PropertyRunDataDTO dto){
		PropertyRunData propertyRunData = BeanUtil.copyProperties(dto, PropertyRunData.class);
		this.save(propertyRunData);
		return propertyRunData.getId();
	}

	/**
	 * 通过主键修改
	 */
	@Override
	public void upd(PropertyRunDataDTO dto){
		PropertyRunData propertyRunData = BeanUtil.copyProperties(dto, PropertyRunData.class);
	    this.updateById(propertyRunData);
	}

}



